package com.tom.architect.day19.simple2;


import com.tom.architect.day19.simple2.handler.AbsUserSystemHandler;
import com.tom.architect.day19.simple2.handler.UserInfo;

import java.util.ArrayList;
import java.util.List;

public class NYUserSystem extends AbsUserSystemHandler {

    private List<UserInfo> userInfos;

    public NYUserSystem() {
        userInfos = new ArrayList<>();
        userInfos.add(new UserInfo("awwa", "123", "1", "0"));
        userInfos.add(new UserInfo("wqe", "124", "2", "1"));
        userInfos.add(new UserInfo("ctrc", "125", "3", "1"));
    }

    @Override
    public UserInfo queryUserInfo(String userName, String userPwd) {
        for (UserInfo userInfo : userInfos) {
            if (userInfo.userName.equals(userName) && userInfo.userPwd.equals(userPwd)) {
                return userInfo;
            }
        }
        AbsUserSystemHandler nextHandler = getNextHandler();
        if (nextHandler != null) {
            return nextHandler.queryUserInfo(userName, userPwd); // 交给下一个
        }
        return null;
    }

}
